<?php

	if(!defined('YMT')) exit;

	/**
	 * @package Yomm
	 * @author bsuter
	 *
	 */
	Class Yomm_Db_Query Extends Yomm_Db_Server {
		
		static private $instance = null;
		
		public function __construct()
		{
			if(!class_exists("mysqli"))
			{
				throw new Yomm_Error("The MySQLi class is not available on this server! Install the Module or Upgrade your PHP Version!");
				return;
			}
		}
		
		/**
		 * Singleton getInstance method to avoid multiple objects of same class
		 */
		public static function getInstance()
		{
			if(is_null(self::$instance))
			{
				self::$instance = new self;
			}
			
			return self::$instance;
		}
		
		public function __call($method, $args)
		{
			$_plugin_class = "Yomm_Db_Plugin_" . ucfirst($method);
			
			// make a reflection object 
			$reflectionObj = new ReflectionClass($_plugin_class); 
			
			// use Reflection to create a new instance, using the $args 
			$_plugin_class = $reflectionObj->newInstanceArgs($args); 
			
			$_plugin_return = $_plugin_class->returnValue();
			
			if(!is_null($_plugin_return))
			{
				return $_plugin_return;
			}
			
			return $this;
		}
	}